// const { json } = require("body-parser");

// 导航
let box = document.querySelector(".box");
let nav = document.querySelector(".top");
let nav2 = document.querySelector(".top2");
let btn = document.querySelector(".btn");
let daohang = nav.querySelector(".daohang");
let lis = daohang.querySelectorAll("ul li");

// 点击切换至登录页面
btn.onclick = function () {
  location.href = "../html/login.html";
};

// 点击切换导航栏高亮
lis.forEach(function (item, index) {
  item.onclick = function () {
    if (index == 0) {
      location.href = "../html/shouye.html";
    }
    if (index == 1) {
      location.href = "../html/shouye.html#matter1";
    }
    if (index == 2) {
      location.href = "../html/wisdom.html";
    }
    if (index == 3) {
      location.href = "../html/course.html";
    }
    if (index == 4) {
      location.href = "../html/tool.html";
    }
   
  };
});

// 回到顶部
let customerService = document.querySelector(".customerService");
let back_top = customerService.querySelector(".back_top");

window.onscroll = function () {
  // 滚动到450显示回到顶部按钮
  if (!(scrollY >= 450)) {
    back_top.style.display = "none";
    return;
  }
  back_top.style.display = "block";
};

// 点击回到顶部
back_top.onclick = function () {
  scrollTo({ top: 0, behavior: "smooth" });
};

// 点击跳转登录页面
btn.onclick = function () {
  location.href = "../html/login.html";
};

// 热门标签
// https://tobadmin.e.360.cn/api/v1/product/GetHot
// 精选
// https://tobadmin.e.360.cn/api/v1/product/GetSelect
// 最热
// https://tobadmin.e.360.cn/api/v1/product/GetHotTag
// case
//  https://tobadmin.e.360.cn/api/v1/product/GetProductListFront?class_type1=&class_type2=&class_type7=&hot_tag=&limit=20&page=1

Hot();
async function Hot() {
  let data = await pAjax({
    url: "/api/v1/product/GetHot",
  });
  //   let { suggest_list } = JSON.parse(data);
  //   console.log(suggest_list);
  let res = JSON.parse(data);
  console.log(res);
}

// 左边案例展示
let caseShow = document.querySelector(".caseShow");
let cases = document.querySelector(".case");

GetProductListFront.forEach((item) => {
  let str = `<dis class="caselist">
              <div
                class="img"
                style="
                  background-image: url('${item.main_pic_url}');
                "
              ></div>
              <div class="liR">
                <h3>${item.title}</h3>
                <div class="liRtag">
                ${item.tags
                  .map((item1, index) => {
                    if (index == 0) {
                      return `<span>${item1.name}</span>`;
                    } else if (index == 1) {
                      return `<span>${item1.name}</span>`;
                    }
                  })
                  .join("")}
                </div>
                <p>
                 ${item.summary}
                </p>
                <div class="time">
                  <img
                    src="	https://s5.ssl.qhimg.com/static/efff36e2918def8a.svg"
                    alt=""
                  />
                  <span>${item.views}</span>
                  <img
                    src="	https://s0.ssl.qhimg.com/static/cb10fc38fe75e8eb.svg"
                    alt=""
                  />
                  <span>${item.create_time}</span>
                </div>
              </div>
            </dis>`;
  cases.innerHTML += str;
});

// 热门
let right = document.querySelector(".reght");
let hot = document.querySelector(".hot");
datalist_Hot.forEach((item) => {
  let str = `
  <div class="hotnav">
                <a href="">${item.title}</a>
              </div>`;
  hot.innerHTML += str;
});

// 精选
let sift = document.querySelector(".sift");
GetSelect.forEach((item) => {
  let str = ` <a href="" class="sift-list">
                <div
                  style="
                    background-image: url(${item.main_pic_url});
                  "
                ></div>
                <p>${item.title}</p>
              </a>`;
  sift.innerHTML += str;
});

// 热门标签
let hottag = document.querySelector(".hottag");
let sortnav1 = hottag.querySelector(".sortnav1");
let h = document.querySelector(".h");

GetHotTag.forEach((item) => {
  let str = "";
  str = `<p>${item.name}</p>`;
  h.innerHTML += str;
});
